function [ModelFiles, ModelIters] = getModelFiles(model_path, prefix, iters)

%%
if isempty(prefix)
%     model_files = dir(fullfile(model_path, '*.caffemodel'));
%     prefix = mycaffe.get_snapshot_prefix(model_files(1).name);
    [SplitedModelFiles, IterList] = mycaffe.splitModelFiles(model_path);
else
    ModelFiles = dir(fullfile(model_path, [prefix '*.caffemodel']));
    [SplitedModelFiles, IterList] = mycaffe.splitModelFiles(ModelFiles);
end

if isempty(SplitedModelFiles)
    throw(MException('getModelFiles:EmptyModels', 'Caffe Model is empty!'))
end

ModelFiles = SplitedModelFiles{1};
ModelIters = IterList{1};

%%
% niter = length(iters);
% if niter == 1
%     iters = [iters iters ModelIters(end)];
% elseif niter == 2
%     iters = [iters ModelIters(end)];
% end
% iters = iters(1) : iters(2) : iters(end);

%%
if isempty(iters), return; end
try
    if length(iters) == 2 && iters(2) == Inf
        k = find(ModelIters == iters(1));
        idx = k : length(ModelIters);
        ModelIters = ModelIters(idx);
    else
        [ModelIters, idx] = intersect(ModelIters, iters);
    end
catch me
    disp(me);
end


ModelFiles = ModelFiles(idx);
if length(ModelIters) < length(iters)
    loss_iters = sprintf('%d ', setdiff(iters, ModelFiles));
    warning('The following iters do not exist in the model path "%s":\n  %s', model_path, loss_iters)
end
